package com.gcb.email;

import java.io.UnsupportedEncodingException;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;

public class TestSimpleMail {

	/**
	 * @param args void
	 * @author Cre.Gu at 2012-5-17
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JavaMailSenderImpl sender = new JavaMailSenderImpl();
		sender.setHost("smtp.sina.com");
		sender.setUsername("guchenbo_work@sina.com");
		//sender.setUsername("guchenbo@gmail.com");
		sender.setPassword("guchenbo");
		final String to = "aa3636@126.com";
		final String from = "guchenbo_work@sina.com";
		final String subject = "会员密码找回信息";
		final String text = "<html><head></head><body><div class=\"CVMain\">" +
				"<div id=\"CVMainbox\"><div><div id=\"CVheader\">" +
				"<div id=\"CVheaderLOGO\"><img src=\"${base}/res/person/images" +
				"/companyLogo.gif\" width=\"143\" height=\"55\"></div>" +
				"<div id=\"CVheaderText\"><p class=\"CVheaderText1\">简历编号：" +
				"<br>${(ccw1.cccw10)!}</p><p class=\"CVheaderText2\">更新日期：" +
				"${(ccw1.aae136)!}</p><p class=\"CVheaderText3\">" +
				"<img src=\"http://www.csrc91.com/person/images/dayin.gif\" " +
				"align=\"absmiddle\" width=\"19\" height=\"18\">" +
				"<a class=\"CVheaderBLUE\" href=\"javascript:window.print();\">" +
				"打印简历</a>（A4纸张）</p></div></div></body></html>";
		sender.send(new MimeMessagePreparator() {
			public void prepare(MimeMessage mimeMessage)
					throws MessagingException, UnsupportedEncodingException {
				MimeMessageHelper msg = new MimeMessageHelper(mimeMessage,
						true, "gb2312");
				msg.setSubject(subject);
				msg.setTo(to);
				msg.setFrom(from);
				msg.setText(text, true);
			}
		});
		System.out.println("it's ok!");
	}

}
